//
//  USTabBarController.m
//  us
//
//  Created by karry on 2025/4/8.
//

#import "USTabBarController.h"
#import "USChatController.h"
#import "MatchViewController.h"
#import "USPhotoController.h"
@interface USTabBarController ()<UITabBarControllerDelegate>

@end

@implementation USTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tabBar.tintColor = UIColor.blackColor;
    self.tabBar.barTintColor = [UIColor mi_2_color];
    
    UITabBarAppearance *appearance = [[UITabBarAppearance alloc] init];
    [appearance configureWithOpaqueBackground]; // 保证背景不透明
    appearance.backgroundColor = [UIColor mi_2_color]; // 设置背景色
    
    
    // 去掉顶部阴影线（分割线）
//    appearance.shadowImage = [UIImage imageNamed:@"character_line"];
    //appearance.shadowColor = [UIColor lightGrayColor];
    appearance.shadowImage = [UIImage jk_imageWithColor:[UIColor mi_2_color]];
    self.tabBar.standardAppearance = appearance;
    self.tabBar.scrollEdgeAppearance = appearance;
    
    
    self.delegate = self;
    
    self.tabBar.unselectedItemTintColor = UIColor.redColor;
    
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    
    NSUInteger index = [tabBarController.viewControllers indexOfObject:viewController];
    if (index == 1) {
        [self gotoPhoto];
        return NO; // 阻止默认切换
    }else if (index == 2) {
        [self gotoChat];
        return NO; // 阻止默认切换
    }
    return YES; // 其他 tab 正常切换
}
- (void)gotoPhoto {
    UINavigationController *nav = (UINavigationController *)self.selectedViewController;
    if (USUser.user.relStatus == 1) {
        USPhotoController *vc = [USPhotoController new];
        [nav pushViewController:vc animated:YES];
        
    }else {
        MatchViewController *vc = [[MatchViewController alloc]init];
        [nav pushViewController:vc animated:YES];
    }
}
- (void)gotoChat {
    UINavigationController *nav = (UINavigationController *)self.selectedViewController;
    if (USUser.user.relStatus == 1) {
        USChatController *vc = [USChatController new];
        vc.conversationId = USUser.user.relImUserName;
        [nav pushViewController:vc animated:YES];
        
    }else {
        MatchViewController *vc = [[MatchViewController alloc]init];
        [nav pushViewController:vc animated:YES];
    }
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
